package day19;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 使用缓冲流复制一个java文件
 * @author wangbiao
 *
 */
public class CopyTextByBuffer {

	
	public static void main(String[] args) {
		
		FileReader fr = null;
		FileWriter fw = null;
		
		BufferedReader br = null;
		BufferedWriter bw = null;
		
		try {
			fr = new FileReader("D:\\MyProject\\javatest\\src\\day19\\BufferedWriterDemo.java");
			fw = new FileWriter("d:\\copytext.txt");
			
			br = new BufferedReader(fr);
			bw = new BufferedWriter(fw);
			String line = null;
			while ((line = br.readLine()) != null) {
				bw.write(line);
				bw.newLine();
				bw.flush();
			}
		} catch (FileNotFoundException e) {
			throw new RuntimeException("读写的文件没有不存在！");
		} catch (IOException e) {
			throw new RuntimeException("读写失败！");
		} finally {
			if (null != br) {
				try {
					br.close();
				} catch (IOException e) {
					throw new RuntimeException("读取流关闭失败！");
				} finally {
					if (null != bw) {
						try {
							bw.close();
						} catch (IOException e) {
							throw new RuntimeException("写入流关闭失败！");
						}
					}
				}
			}
		}
	}

}
